package com.orange.powerdownload.learn;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * Description:
 */
public class PoolTest01 {
    public static void main(String[] args) {
        //创建线程池对象
        ThreadPoolExecutor threadPool = new ThreadPoolExecutor(
                2
                , 3
                , 1
                , TimeUnit.SECONDS
                , new ArrayBlockingQueue<>(2)
                /*,(r)->{
                    Thread t = new Thread(r);
                    return t;
                }*/
        );

        //创建任务
        Runnable r = () -> {
            System.out.println(Thread.currentThread().getName());
        };

        //将任务提交给线程池
        for (int i = 0; i < 5; i++) {
            threadPool.execute(r);
        }
    }
}
